Skip to content

fix(menu): map fallback highlights to original graphemes - #1303

Open
Rajatendu1 wants to merge 1 commit into
nushell:mainfrom
Rajatendu1:fix-unicode-fallback-highlights
Open

Rajatendu1 wants to merge 1 commit into
nushell:mainfrom
Rajatendu1:fix-unicode-fallback-highlights

Conversation

@Rajatendu1

Copy link
Copy Markdown

Summary

Fix Reedline's fallback completion highlighting when a completer does not supply match_indices.

get_match_indices searches a lowercased string, where find returns a UTF-8 byte offset. style_suggestion consumes original grapheme indices. Passing that offset through shifts underlining after non-ASCII text, and lowercase expansions can shift it again.

The change maps the matched lowercased byte range onto the original graphemes it overlaps. It keeps the existing whole-string lowercase search, leaves provided indices borrowed and unchanged, and keeps empty/no-match results empty. A substring that matches part of a displayed grapheme highlights that entire grapheme.

No public API signature changes. No new dependencies.

Related: nushell/nushell#17450. This fixes the Reedline fallback, not completion providers that compute their own indices.

Before

numéro.txt with query ro underlines o.. An emoji prefix can leave the match unhighlighted.

After

The same query underlines ro. Emoji, combining characters and lowercase length changes map back to the displayed text.

Additional notes

18 added cases cover ASCII controls, accented/CJK/emoji prefixes, combining marks, CRLF, dotted-I expansion, Kelvin-sign contraction, contextual Greek lowercasing, empty/no match, explicit indices, and the actual styled output.

Local Linux validation with Rust 1.95.0, base 14be1e0:

  • Clean all-feature library baseline: 2,312 passed, 3 ignored.
  • Added regressions against unchanged source: 10 failed; after the fix all pass.
  • cargo test --all-targets --all-features --locked: 2,330 library tests passed, 3 ignored; example test targets passed.
  • cargo test --doc --all-features --locked: 32 passed.
  • cargo nextest run --all --all-features: 2,330 passed, 3 skipped.
  • cargo clippy --locked --all-targets --all-features -- -D warnings, formatting, git diff --check, and warning-free all-feature docs: passed.
  • A separate consumer program exercised the public matcher and styling functions before and after.

Not run: Windows/macOS or the full Nushell application. ANSI-decorated display-override matching and Unicode normalization/case-folding are unchanged and outside this patch.

Patch prepared and tests executed by Instinct, an AI assistant, at my request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant